@model GrantsViewModel
@{
    ViewData["Title"] = "客户端授权";
}

<div class="row justify-content-md-center">
    <div class="col-sm-8">
        <div class="grants-page">
            <div class="lead">
                <h1>客户端授权</h1>
                <p>下面列出了您已授予权限的应用程序及其可以访问的资源。</p>
            </div>

            @if (Model.Grants.Any() == false)
            {
                <div class="row">
                    <div class="col-sm-12">
                        <div class="alert alert-info">
                            您尚未授予访问任何应用程序的权限
                        </div>
                    </div>
                </div>
            }
            else
            {
                foreach (var grant in Model.Grants)
                {
                    <div class="card">
                        <div class="card-header">
                            <div class="col-sm-3 card-title">
                                @if (grant.ClientLogoUrl != null)
                                {
                                    <img src="@grant.ClientLogoUrl">
                                }
                                <strong>@grant.ClientName</strong>
                            </div>

                            <div class="col-sm-4">
                                <form asp-action="Revoke">
                                    <input type="hidden" name="clientId" value="@grant.ClientId">
                                    <button class="btn btn-danger">撤消访问</button>
                                </form>
                            </div>
                        </div>

                        <ul class="list-group list-group-flush">
                            @if (grant.Description != null)
                            {
                                <li class="list-group-item">
                                    <label>描述:</label> @grant.Description
                                </li>

                            }
                            <li class="list-group-item">
                                <label>创建日期:</label> @grant.Created.ToString("yyyy-MM-dd")
                            </li>
                            @if (grant.Expires.HasValue)
                            {
                                <li class="list-group-item">
                                    <label>过期时间:</label> @grant.Expires.Value.ToString("yyyy-MM-dd")
                                </li>
                            }
                            @if (grant.IdentityGrantNames.Any())
                            {
                                <li class="list-group-item">
                                    <label>身份授权</label>
                                    <ul>
                                        @foreach (var name in grant.IdentityGrantNames)
                                        {
                                            <li>@name</li>
                                        }
                                    </ul>
                                </li>
                            }
                            @if (grant.ApiGrantNames.Any())
                            {
                                <li class="list-group-item">
                                    <label>API授权</label>
                                    <ul>
                                        @foreach (var name in grant.ApiGrantNames)
                                        {
                                            <li>@name</li>
                                        }
                                    </ul>
                                </li>
                            }
                        </ul>
                    </div>
                }
            }
        </div>
    </div>
</div>

